package com.heny.nc.service;

import com.heny.demo.common.CommonErrorCode;
import com.heny.demo.common.CommonException;
import org.apache.commons.lang3.StringUtils;

/**
 * @author litao.cc
 * @version SaveDataProcessorStrategyEnum.java v0.1 2025/4/26 18:47
 * @date 2025/4/26 18:47
 * @description SaveDataProcessorStrategyEnum
 */
public enum SaveDataProcessorEnum {
    EXL("exl", new ExlProcessor()),
    TXT("txt", new TxtProcessor()),
    DAT("dat", new DatProcessor()),
    ;

    private final String type;

    private final AbstractSaveDataProcessor processor;

    SaveDataProcessorEnum(String type, AbstractSaveDataProcessor strategy) {
        this.type = type;
        this.processor = strategy;
    }

    public String getType() {
        return type;
    }

    public AbstractSaveDataProcessor getProcessor() {
        return processor;
    }

    public static SaveDataProcessorEnum getByType(String type) {
        if (StringUtils.isBlank(type)) {
            throw new CommonException(CommonErrorCode.SYSTEM_ERROR, "type is null");
        }
        for (SaveDataProcessorEnum item : values()) {
            if (StringUtils.equals(type, item.getType())) {
                return item;
            }
        }
        throw new CommonException(CommonErrorCode.PARAM_VALIDATION_FAILED, "不支持的文件存储类型,未找到对应处理策略");
    }
}
